home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
System Booster
/
System Booster.iso
/
Archives
/
GNU
/
groff_src.lha
/
groff-1.10src
/
libgroff
/
prime.cc
< prev
next >
Encoding:
Amiga
Atari
Commodore
DOS
FM Towns/JPY
Macintosh
Macintosh JP
Macintosh to JP
NeXTSTEP
RISC OS/Acorn
Shift JIS
UTF-8
Wrap
C/C++ Source or Header
|
1991-05-20
|
385 b
|
27 lines
#include <math.h>
int is_prime(unsigned n)
{
if (n <= 3)
return 1;
if (!(n & 1))
return 0;
if (n % 3 == 0)
return 0;
unsigned lim = unsigned(sqrt((double)n));
unsigned d = 5;
for (;;) {
if (d > lim)
break;
if (n % d == 0)
return 0;
d += 2;
if (d > lim)
break;
if (n % d == 0)
return 0;
d += 4;
}
return 1;
}